home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 March / macformat-022.iso / Shareware City / Developers / Jim's CDEFs v1.30 / demo Source ƒ / demoTab.c < prev    next >
Encoding:
Text File  |  1994-11-06  |  2.5 KB  |  111 lines  |  [TEXT/KAHL]

  1. // -----------------------------------------------------------------------------
  2. //    File        : demoTab.c
  3. //    Date        : November 5, 1994
  4. //    Author        : Jim Stout
  5. //    Purpose        : some tabPanel demonstrations
  6. //
  7. // -----------------------------------------------------------------------------
  8. #include <GestaltEqu.h>
  9.  
  10. #include "demoShell.h"
  11. #include "demoTab.h"
  12. #include "dialogAssist.h"
  13. #include "movableModal.h"
  14. #include "panelAssist.h"
  15.  
  16. #define TABCNTL        3        // ID for Tab control
  17. #define CTLTOKEEP    4        // controls that are on all panels
  18.  
  19. #define FIRSTPANEL    160        // DITL id for "base" panel
  20.  
  21. #define DEMOTAB1    160        // DLOG id's for each demo
  22. #define DEMOTAB2    180
  23. #define DEMOTAB3    190
  24. #define DEMOTAB4    200
  25.  
  26. static pascal char    tabFilter    (DialogPtr theDialog, EventRecord *theEvent, 
  27.                                         short *theItem);
  28.  
  29. extern void demoTab(short demoNum)
  30. {
  31.     DialogPtr    d;
  32.     short        currPanel,toPanel,itemHit;
  33.     GrafPtr        savePort;
  34.     
  35.     if(daGestalt(gestaltDITLExtAttr) == -1L) {
  36.         if(daGestalt(gestaltCTBVersion) < 0x0100) {
  37.             StopAlert(256, nil);
  38.             return;
  39.         }
  40.     }
  41.     switch(demoNum) {
  42.         case iDemoTab1:
  43.             d = GetNewDialog(DEMOTAB1, 0L, (DialogPtr)-1);
  44.         break;
  45.         case iDemoTab2:
  46.             d = GetNewDialog(DEMOTAB2, 0L, (DialogPtr)-1);
  47.         break;
  48.         case iDemoTab3:
  49.             d = GetNewDialog(DEMOTAB3, 0L, (DialogPtr)-1);
  50.         break;
  51.         case iDemoTab4:
  52.             d = GetNewDialog(DEMOTAB4, 0L, (DialogPtr)-1);
  53.         break;
  54.     }
  55.     if(d) {
  56.         GetPort(&savePort);
  57.         SetPort(d);    
  58.         
  59.         toPanel = daGetCtlValue(d, TABCNTL);
  60.     
  61.         panelSwap(d, FIRSTPANEL, currPanel, toPanel, CTLTOKEEP);
  62.         
  63.         currPanel = toPanel;
  64.         
  65.         ShowWindow(d);
  66.                 
  67.         do {
  68.             movableModalDialog((ModalFilterProcPtr)tabFilter,&itemHit);
  69.             
  70.             if(itemHit == TABCNTL) {
  71.                 toPanel = daGetCtlValue(d, TABCNTL);
  72.                 if(toPanel != currPanel) {
  73.                     panelSwap(d, FIRSTPANEL, currPanel, toPanel, CTLTOKEEP);
  74.                     currPanel = toPanel;
  75.                 }
  76.             
  77.             }
  78.         }while(itemHit != ok && itemHit != cancel);
  79.         DisposDialog(d);
  80.         SetPort(savePort);
  81.     }
  82. }
  83.  
  84. static pascal char    tabFilter    (DialogPtr theDialog, EventRecord *theEvent, 
  85.                                         short *theItem)
  86. {
  87.     char             c, result = FALSE;
  88.     
  89.     switch(theEvent->what) {
  90.         case keyDown:
  91.          case autoKey:
  92.          
  93.              c = theEvent->message & charCodeMask;
  94.              
  95. // check for an exit key, really should put this into movableModal…
  96.  
  97.              if(result = daExitKey(theDialog, theEvent, theItem, cancel))
  98.                  break;
  99.                  
  100. // check for cmd or cntl TAB to switch panels
  101.                  
  102.             if(theEvent->modifiers & controlKey ||
  103.                 theEvent->modifiers & cmdKey) {
  104.                  if(result = panelCmdTab(theDialog, TABCNTL, c, theItem))
  105.                      break;
  106.              }
  107.          break;
  108.      }
  109.      return(result);
  110. }
  111.